package superdashboard;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;

public class DataReceiver implements Runnable {
	private DatagramSocket socket;
	byte [][][] packets;
	public DataReceiver(DatagramSocket socket) {
		this.socket = socket;
		//packets = new LinkedBlockingQueue();
		 packets = new byte[640][480][3];
	}

	@Override
	public void run() {
		while(true) {
			DatagramPacket packet = new DatagramPacket(new byte[1444], 1444);
			try {
				socket.receive(packet);
			} catch (IOException e) {
				e.printStackTrace();
			}
			try{
				byte[] data = packet.getData();
				DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(data));
				int colum = inputStream.readInt();
				for (int a = 0; a < packets[0].length; a++){
					packets[colum][a][0] = inputStream.readByte();
					packets[colum][a][1] = inputStream.readByte() ;
					packets[colum][a][2] = inputStream.readByte();
				}
				if (colum == 100)
					System.out.println("packets recieved");
			}catch(Exception e){
				e.printStackTrace();
			}
		
			
		}
	}
	public byte[][][] getData(){
		return packets;
	}
}
